package com.work.formaldehyde.homefragment;

import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.umeng.analytics.MobclickAgent;
import com.work.formaldehyde.R;
import com.work.formaldehyde.activity.JianCeJiLuActivity;
import com.work.formaldehyde.activity.KePuXQActivity;
import com.work.formaldehyde.activity.LoginActivity;
import com.work.formaldehyde.activity.ShangPingActivity;
import com.work.formaldehyde.activityadapter.JianCeListAdapter;
import com.work.formaldehyde.copyweatherview.WeatherItemView;
import com.work.formaldehyde.copyweatherview.WeatherModels1;
import com.work.formaldehyde.copyweatherview.sWeatherView;
import com.work.formaldehyde.model.JianCeBanner;
import com.work.formaldehyde.model.JianCeDateModel;
import com.work.formaldehyde.model.ShangPingModel;
import com.work.formaldehyde.util.ApiUtils;
import com.work.formaldehyde.util.Url;
import com.work.formaldehyde.view.LineView;
import com.work.formaldehyde.view.LineViews;
import com.work.formaldehyde.view.TableView;
import com.work.formaldehyde.view.ZzWeatherView;
import com.xujiaji.happybubble.BubbleDialog;
import com.xujiaji.happybubble.BubbleLayout;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class JianceFragment extends Fragment implements View.OnClickListener, OnBannerListener, AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
    //用于获取视图
    private View root;
    //页面顶部banner
    private Banner jiance_banner;
    private sWeatherView weatherViews;//天气折线视图
    private RelativeLayout kp_title;
    private RelativeLayout shidu, wendu, year_jilu;
    private ImageView floatbutton;
    public static SwipeRefreshLayout swipeLayout;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        root = inflater.inflate(R.layout.jiance_listhead, container, false);//初始加载
        Init();
        if (ApiUtils.isNetworkConnected(getActivity()))
            InitView(root);
        return root;
    }

    private ShangPingModel shangPingModel;
    public static ArrayList<ShangPingModel.data> list1 = new ArrayList<>();
    private ArrayList<String> new_list_views;
    private List<WeatherModels1> lists;
    private WeatherModels1 models;
    public static  ListView kepu_list;

    //做上角的三个控件
    private ImageView qiwen_img;
    private TextView location_qiwen, location;
    public static boolean getliebiao = false;

    @Override
    public void onResume() {
        super.onResume();
//        if (getliebiao) {
//            okHttp_huatu();
//            getliebiao = false;
//            mts.addWave(ContextCompat.getColor(getActivity(), R.color.home_bottom_text_color_ischeck), false, zhuwo);
//            mts.addWave(ContextCompat.getColor(getActivity(), R.color.red), false, ciwo);
//            mts.addWave(ContextCompat.getColor(getActivity(), R.color.contaminated_yellow), false, keting);
//            mts.addWave(ContextCompat.getColor(getActivity(), R.color.contaminated_green), false, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f);
//            year_jilu.addView(mts);
//        }
    }

    /**
     * 初始加载视图
     */
    public void Init() {
        Map<String, Object> music = new HashMap<String, Object>();
        music.put("检测页面", "1");//自定义参数：音乐类型，值：流行
        MobclickAgent.onEventObject(getActivity(), "testing", music);

    }

    public int sswudi = 0;

    public void dateup(View v) {
        lists = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            models = new WeatherModels1();
            switch (i) {
                case 1:
                    sswudi = 3;
                    break;
                case 2:
                    sswudi = 2;
                    break;
                case 3:
                    sswudi = 4;
                    break;
                case 4:
                    sswudi = 5;
                    break;
                case 5:
                    sswudi = 6;
                    break;
                case 6:
                    sswudi = 8;
                    break;
                case 7:
                    sswudi = 10;
                    break;
                case 8:
                    sswudi = 11;
                    break;
                case 9:
                    sswudi = 10;
                    break;
                case 10:
                    sswudi = 8;
                    break;
                case 11:
                    sswudi = 5;
                    break;
                case 12:
                    sswudi = 3;
                    break;
            }
            models.setNightTemp(sswudi); //温度折线
            models.setWindLevel(i + "月"); //
            lists.add(models);
        }
        weather(v);
    }

    public void weather(View v) {
        weatherViews = v.findViewById(R.id.weather_views);
        weatherViews.setList(lists);
        weatherViews.setLineType(ZzWeatherView.LINE_TYPE_CURVE);
        weatherViews.setLineWidth(11f);
        weatherViews.setOnWeatherItemClickListener(new sWeatherView.OnWeatherItemClickListener() {
            @Override
            public void onItemClick(WeatherItemView itemView, int position, WeatherModels1 weatherModel) {
                int y = (int) (ApiUtils.HEIGHT - ApiUtils.HEIGHT * (weatherModel.getNightTemp() - ApiUtils.MIN_LINE) * 1.0f / (ApiUtils.MAX_LINE - ApiUtils.MIN_LINE)) + ApiUtils.TEXT_SIZE * 2;
                int x = ApiUtils.WIDTH;
                String itemstr = GETSTRING(position);
                windows(getActivity(), itemView, itemstr, GETPOSITION(y, position));
            }
        });
        shidu = v.findViewById(R.id.shidu);
        wendu = v.findViewById(R.id.wendu);
        year_jilu = v.findViewById(R.id.year_jilu);
        mts = new TableView(getActivity());
        // 初始化数据表格相关
        mts.setupCoordinator("月", "", 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f);
        mts.addWave(ContextCompat.getColor(getActivity(), R.color.contaminated_violet), false, beizhu);
        mts.addWave(ContextCompat.getColor(getActivity(), R.color.home_bottom_text_color_ischeck), false, zhuwo);
        mts.addWave(ContextCompat.getColor(getActivity(), R.color.red), false, ciwo);
        mts.addWave(ContextCompat.getColor(getActivity(), R.color.contaminated_yellow), false, keting);
        mts.addWave(ContextCompat.getColor(getActivity(), R.color.contaminated_green), false, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f);
        year_jilu.addView(mts);
        year_jilu.setVisibility(View.GONE);
        kepu_list.setOnItemClickListener(this);
    }

    public String GETSTRING(int position) {
        String itemstr = "";
        switch (position) {
            case 0:
                return "0.035mg/m³";
            case 1:
                return "0.030mg/m³";
            case 2:
                return "0.040mg/m³";
            case 3:
                return "0.055mg/m³";
            case 4:
                return "0.070mg/m³";
            case 5:
                return "0.105mg/m³";
            case 6:
                return "0.118mg/m³";
            case 7:
                return "0.122mg/m³";
            case 8:
                return "0.117mg/m³";
            case 9:
                return "0.085mg/m³";
            case 10:
                return "0.058mg/m³";
            case 11:
                return "0.033mg/m³";
        }
        return itemstr;
    }

    public int GETPOSITION(int y, int position) {
        int posi = 0;
        switch (position) {
            case 0:
                return ((y - 5) / 2) - (14 - position);
            case 1:
                return ((y - 5) / 2);
            case 2:
                return ((y - 5) / 2) - (20 - position);
            case 3:
                return ((y - 5) / 2) - (40 - position);
            case 4:
                return ((y - 5) / 2) - (40 - position);
            case 5:
                return ((y - 5) / 2) - (60 - position);
            case 6:
                return ((y - 5) / 2) - (80 - position);
            case 7:
                return ((y - 5) / 2) - (90 - position);
            case 8:
                return ((y - 5) / 2) - (80 - position);
            case 9:
                return ((y - 5) / 2) - (60 - position);
            case 10:
                return ((y - 5) / 2) - (40 - position);
            case 11:
                return ((y - 5) / 2) - (18 - position);
        }
        return posi;
    }

    private LineView headView;
    private LineViews lineViews;
    private TableView mts;

    /**
     * 初始加载视图
     */
    public void InitView(View v) {
        floatbutton = v.findViewById(R.id.floatbutton);
        floatbutton.setOnClickListener(this);
        swipeLayout = v.findViewById(R.id.swipe_container);
        kepu_list = v.findViewById(R.id.jiance_list);
        View view = getActivity().getLayoutInflater().inflate(
                R.layout.fragment_jiance, kepu_list, false);
        kepu_list.addHeaderView(view);
        jiance_banner = view.findViewById(R.id.jiance_banner);
        dateup(view);
        qiwen_img = view.findViewById(R.id.qiwen_img);
        location_qiwen = view.findViewById(R.id.location_qiwen);
        location = view.findViewById(R.id.location);
        qiwen_img.setOnClickListener(this);
        weatherViews.smoothScrollTo(0, 0);
        kp_title = view.findViewById(R.id.kp_title);
        int titleheight = ApiUtils.getStatusBarHeight(getActivity());
        kp_title.setPadding(0, titleheight, 0, 0);
        headView = view.findViewById(R.id.lineView);
        headView.setData(
                Arrays.asList("12℃", "17℃", "22℃", "27℃"),
                Arrays.asList(0.23f, 0.31f, 0.4f, 0.55f));
        headView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                windows(getActivity(), headView, "0.23℃  0.31℃  0.4℃  0.55℃");
            }
        });
        lineViews = view.findViewById(R.id.lineViews);
        lineViews.setData(
                Arrays.asList("15%", "25%", "35%", "45%"),
                Arrays.asList(0.23f, 0.31f, 0.4f, 0.55f));
        lineViews.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                windows(getActivity(), lineViews, "0.23%  0.31%  0.4%  0.55%");
            }
        });
        okHttp_postFromParameters();
        okHttp_postFromParameters1();
        okHttp_huatu();
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorSchemeResources(android.R.color.holo_orange_dark,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);

    }


    public void getlist() {
        if (jcdmodel.size() != 0) {
            for (int sd = 0; sd < jcdmodel.size(); sd++) {
                if (jcdmodel.get(sd).getRoom().equals("主卧")) {
                    if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("01")){
                        zhuwo[0] = Float.valueOf(jcdmodel.get(sd).getHcho());
                    }else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("02")){
                        zhuwo[1] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("03")){
                        zhuwo[2] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("04")){
                        zhuwo[3] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("05")){
                        zhuwo[4] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("06")){
                        zhuwo[5] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("07")){
                        zhuwo[6] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("08")){
                        zhuwo[7] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("09")){
                        zhuwo[8] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("10")){
                        zhuwo[9] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("11")){
                        zhuwo[10] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("12")){
                        zhuwo[11] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else{
                        zhuwo[zhuwoint] =0;
                    }
                    zhuwoint++;
                } else if (jcdmodel.get(sd).getRoom().equals("次卧")) {
                    if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("01")){
                        ciwo[0] = Float.valueOf(jcdmodel.get(sd).getHcho());
                    }else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("02")){
                        ciwo[1] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("03")){
                        ciwo[2] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("04")){
                        ciwo[3] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("05")){
                        ciwo[4] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("06")){
                        ciwo[5] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("07")){
                        ciwo[6] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("08")){
                        ciwo[7] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("09")){
                        ciwo[8] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("10")){
                        ciwo[9] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("11")){
                        ciwo[10] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("12")){
                        ciwo[11] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else{
                        ciwo[ciwoint] =0;
                    }
                    ciwoint++;
                } else if (jcdmodel.get(sd).getRoom().equals("客厅")) {
                    if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("01")){
                        keting[0] = Float.valueOf(jcdmodel.get(sd).getHcho());
                    }else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("02")){
                        keting[1] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("03")){
                        keting[2] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("04")){
                        keting[3] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("05")){
                        keting[4] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("06")){
                        keting[5] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("07")){
                        keting[6] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("08")){
                        keting[7] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("09")){
                        keting[8] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("10")){
                        keting[9] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("11")){
                        keting[10] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("12")){
                        keting[11] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else{
                        keting[ketingint] =0;
                    }
                    ketingint++;
                }else  {
                    if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("01")){
                        beizhu[0] = Float.valueOf(jcdmodel.get(sd).getHcho());
                    }else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("02")){
                        beizhu[1] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("03")){
                        beizhu[2] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("04")){
                        beizhu[3] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("05")){
                        beizhu[4] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("06")){
                        beizhu[5] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("07")){
                        beizhu[6] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("08")){
                        beizhu[7] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("09")){
                        beizhu[8] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("10")){
                        beizhu[9] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("11")){
                        beizhu[10] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else if(jcdmodel.get(sd).getTimes().substring(5, 7).equals("12")){
                        beizhu[11] = Float.valueOf(jcdmodel.get(sd).getHcho());}
                    else{
                        beizhu[beizhuint] =0;
                    }
                    beizhuint++;
                }
            }
        }
    }

    public void windows(Context context, View view, String apistr, int y) {
        BubbleLayout bl = new BubbleLayout(context);
        bl.setBubbleColor(getResources().getColor(R.color.bubble_color));
        View popupwindowview = LayoutInflater.from(context).inflate(
                R.layout.window_bubble, null);
        TextView item_bubble = popupwindowview.findViewById(R.id.item_bubble);
        item_bubble.setText(apistr);
        new BubbleDialog(context)
                .addContentView(popupwindowview)
                .setClickedView(view)
                .calBar(true).setOffsetY(y).setTransParentBackground()
                .setBubbleLayout(bl)
                .show();
    }

    public void windows(Context context, View view, String apistr) {
        BubbleLayout bl = new BubbleLayout(context);
        bl.setBubbleColor(getResources().getColor(R.color.bubble_color));
        View popupwindowview = LayoutInflater.from(context).inflate(
                R.layout.window_bubble, null);
        TextView item_bubble = popupwindowview.findViewById(R.id.item_bubble);
        item_bubble.setText(apistr);
        new BubbleDialog(context)
                .addContentView(popupwindowview)
                .setClickedView(view)
                .calBar(true).setTransParentBackground()
                .setBubbleLayout(bl)
                .show();
//        new BubbleDialog(context)
//                .addContentView(popupwindowview)
//                .setClickedView(view)
//                .calBar(true)
//                .show();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.qiwen_img:
                break;
            case R.id.floatbutton:
                if (Url.USER_ID.equals("")) {
                    Intent is_login = new Intent(getActivity(), LoginActivity.class);
                    getActivity().startActivity(is_login, ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());
                    ApiUtils.SetToast(getActivity(), "请先登录");
                } else {
                    Intent tojiance = new Intent(getActivity(), JianCeJiLuActivity.class);
                    startActivity(tojiance, ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());
                    Map<String, Object> music = new HashMap<String, Object>();
                    music.put("添加记录按钮", "1");//自定义参数：音乐类型，值：流行
                    MobclickAgent.onEventObject(getActivity(), "addjilu", music);
                }
                break;
        }
    }


    private void initViews() {
        MyImageLoader mMyImageLoader = new MyImageLoader();
        //设置样式，里面有很多种样式可以自己都看看效果
        jiance_banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        //设置图片加载器
        jiance_banner.setImageLoader(mMyImageLoader);
        //设置轮播的动画效果,里面有很多种特效,可以都看看效果。
        jiance_banner.setBannerAnimation(Transformer.DepthPage);
        //轮播图片的文字
        jiance_banner.setBannerTitles(imageTitle);
        //设置轮播间隔时间
        jiance_banner.setDelayTime(3000);
        //设置是否为自动轮播，默认是true
        jiance_banner.isAutoPlay(true);
        //设置指示器的位置，小点点，居中显示
        jiance_banner.setIndicatorGravity(BannerConfig.CENTER);
        //设置图片加载地址
        jiance_banner.setImages(imagePath)
                //轮播图的监听
                .setOnBannerListener(this)
                //开始调用的方法，启动轮播图。
                .start();

    }

    private ArrayList<String> imagePath;
    private ArrayList<String> imageTitle;
    private ArrayList<String> msgtext;

    /**
     * 用于遍历集合
     */
    public void ListInit() {
        imagePath = new ArrayList<>();
        imageTitle = new ArrayList<>();
        msgtext = new ArrayList<>();
        imageTitle.add("我是海鸟一号");
        imageTitle.add("我是海鸟二号");
        imageTitle.add("我是海鸟三号");
        msgtext.add("恭喜【简单爱】完成每日任务，获得0.10元奖");
        msgtext.add("恭喜【简单爱】完成每日任务，获得0.20元奖");
        msgtext.add("恭喜【简单爱】完成每日任务，获得0.30元奖");
    }

    @Override
    public void OnBannerClick(int position) {
        if (!jcbner.getData().get(position).getImg().equals("")) {
            Intent tokpxq = new Intent(getActivity(), KePuXQActivity.class);
            tokpxq.putExtra("id", position + "");
            tokpxq.putExtra("url", jcbner.getData().get(position).getUrl() + "");
            tokpxq.putExtra("num", "3");
            startActivity(tokpxq, ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());
        }
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Intent is_login = new Intent(getActivity(), ShangPingActivity.class);
        is_login.putExtra("id", list1.get(i - 1).getId());
        is_login.putExtra("manjian", list1.get(i - 1).getGoods_discount());
        startActivity(is_login, ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());
    }

    @Override
    public void onRefresh() {
        new Handler().postDelayed(new Runnable() {
            public void run() {
//                for (int ss = 0; ss < 12; ss++) {
//                    zhuwo[ss] = 0;
//                    ciwo[ss] = 0;
//                    keting[ss] = 0;
//                }

                okHttp_huatu();
                year_jilu.removeView(mts);
                mts = null;
                mts = new TableView(getActivity());
                // 初始化数据表格相关
                mts.setupCoordinator("月", "", 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f);
                mts.addWave(ContextCompat.getColor(getActivity(), R.color.home_bottom_text_color_ischeck), false, zhuwo);
                mts.addWave(ContextCompat.getColor(getActivity(), R.color.red), false, ciwo);
                mts.addWave(ContextCompat.getColor(getActivity(), R.color.contaminated_yellow), false, keting);
                mts.addWave(ContextCompat.getColor(getActivity(), R.color.contaminated_green), false, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f, 0.07f);
                year_jilu.addView(mts);
                swipeLayout.setRefreshing(false);
            }
        }, 3000);
    }

    /**
     * 图片加载类
     */
    private class MyImageLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context.getApplicationContext())
                    .load(path)
                    .into(imageView);
        }
    }

    private void okHttp_postFromParameters() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    OkHttpClient okHttpClient = new OkHttpClient();
//                    RequestBody formBody = new FormBody.Builder()
//                            .build();
//                    Request request = new Request.Builder().url(Url.SHANGPINGLIST).post(formBody).build();
//                    okhttp3.Response response = okHttpClient.newCall(request).execute();
//                    String msg = response.body().string();
//                    Message message = new Message();
//                    message.obj = msg;
//                    gethot1.sendMessage(message);
                    Request request = new Request.Builder().get().url(Url.SHANGPINGLIST).build();
                    Call call = okHttpClient.newCall(request);
                    call.enqueue(new Callback() {
                        @Override
                        public void onFailure(Call call, IOException e) {
                        }

                        @Override
                        public void onResponse(Call call, final Response response) {
                            try {
                                final String responseStr;
                                responseStr = response.body().string();
                                Message message = new Message();
                                message.obj = responseStr;
                                gethot1.sendMessage(message);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                } catch (
                        Exception e) {
                    e.printStackTrace();
                }
            }
        }).
                start();
    }

    private void okHttp_postFromParameters1() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    OkHttpClient okHttpClient = new OkHttpClient();
//                    RequestBody formBody = new FormBody.Builder()
//                            .add("type", "jc").build();
//                    Request request = new Request.Builder().url(Url.GETBANNER).post(formBody).build();
//                    okhttp3.Response response = okHttpClient.newCall(request).execute();
//                    String msg = response.body().string();
//                    Message message = new Message();
//                    message.obj = msg;
//                    gethot.sendMessage(message);
                    Request request = new Request.Builder().get().url(Url.GETBANNERS + "jc").build();
                    Call call = okHttpClient.newCall(request);
                    call.enqueue(new Callback() {
                        @Override
                        public void onFailure(Call call, IOException e) {
                        }

                        @Override
                        public void onResponse(Call call, final Response response) {
                            try {
                                final String responseStr;
                                responseStr = response.body().string();
                                Message message = new Message();
                                message.obj = responseStr;
                                gethot.sendMessage(message);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                } catch (
                        Exception e) {
                    e.printStackTrace();
                }
            }
        }).
                start();
    }

    public Handler gethot1 = new Handler() {
        public void handleMessage(android.os.Message msg) {
            JSONObject success_Object;
            try {
                if (msg.obj != null) {
                    success_Object = new JSONObject(msg.obj.toString());
                    String code = success_Object.getString("code");
                    if (code.equals("1")) {
                        Gson gson = new Gson();
                        shangPingModel = gson.fromJson(msg.obj.toString(),
                                ShangPingModel.class);
                        if (shangPingModel.getData().size() > list1.size()) {
                            list1.clear();
                            list1.addAll(shangPingModel.getData());
                        }
                        JianCeListAdapter myAdapter = new JianCeListAdapter(list1,
                                getActivity(), getActivity());
                        kepu_list.setAdapter(myAdapter);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    public static JianCeBanner jcbner;
    public Handler gethot = new Handler() {
        public void handleMessage(android.os.Message msg) {
            JSONObject success_Object;
            try {
                if (msg.obj != null) {
                    success_Object = new JSONObject(msg.obj.toString());
                    String code = success_Object.getString("code");
                    if (code.equals("1")) {
                        Gson gson = new Gson();
                        jcbner = gson.fromJson(msg.obj.toString(),
                                JianCeBanner.class);
                        ListInit();
                        for (int a = 0; a < jcbner.data.size(); a++) {
                            imagePath.add(jcbner.data.get(a).getImg());
                        }
                        initViews();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };


    private void okHttp_huatu() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    OkHttpClient okHttpClient = new OkHttpClient();
//                    RequestBody formBody = new FormBody.Builder().add("uid", Url.USER_ID)
//                            .build();
//                    Request request = new Request.Builder().url(Url.GETCELIANGDATE).post(formBody).build();
//                    okhttp3.Response response = okHttpClient.newCall(request).execute();
//                    String msg = response.body().string();
//                    Message message = new Message();
//                    message.obj = msg;
//                    gethuatu.sendMessage(message);
                    Request request = new Request.Builder().get().url(Url.GETCELIANGS+"?uid=" + Url.USER_ID + "&logintoken=" + Url.LOGIN_TOKEN).build();
                    Call call = okHttpClient.newCall(request);
                    call.enqueue(new Callback() {
                        @Override
                        public void onFailure(Call call, IOException e) {
                        }

                        @Override
                        public void onResponse(Call call, final Response response) {
                            try {
                                final String responseStr;
                                responseStr = response.body().string();
                                Message message = new Message();
                                message.obj = responseStr;
                                gethuatu.sendMessage(message);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                } catch (
                        Exception e) {
                    e.printStackTrace();
                }
            }
        }).
                start();
    }

    private ArrayList<JianCeDateModel.data> jcdmodel = new ArrayList<>();
    int zhuwoint = 0, ciwoint = 0, ketingint = 0,beizhuint=0;
    float[] beizhu = new float[12];
    float[] zhuwo = new float[12];
    float[] ciwo = new float[12];
    float[] keting = new float[12];
    JianCeDateModel jianCeDateModel;
    public Handler gethuatu = new Handler() {
        public void handleMessage(android.os.Message msg) {
            JSONObject success_Object;
            try {
                if (msg.obj != null) {
                    success_Object = new JSONObject(msg.obj.toString());
                    String code = success_Object.getString("code");
                    if (code.equals("1")) {
                        Gson gson = new Gson();
                        jcdmodel.clear();
                        jianCeDateModel = gson.fromJson(msg.obj.toString(),
                                JianCeDateModel.class);
                        jcdmodel.addAll(jianCeDateModel.getData());
                        zhuwoint = 0;
                        ciwoint = 0;
                        ketingint = 0;
                        beizhuint = 0;
                        getlist();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

}